#include<stdlib.h>   
#include<stdio.h>
#include<string.h>
#include<stdint.h>

unsigned LowBit(unsigned x){
    //一个数的相反数就是对它进行取反并加1
    unsigned a = x & ((~x) + 1);

    return a;
}

//return 0不全是由字母组成的
//returu 1全是由字母组成的
unsigned Letter(unsigned x){
    unsigned x1 = x & 0x22222222;
    unsigned x2 = x & 0x44444444;
    unsigned x3 = x & 0x88888888;
    return (x3 >> 3) & ((x2 >> 2) | (x1 >> 1));
}


int main(){

    //16进制：ffffff  -->  10进制：16777215 --> 二进制：111111111111111111111111 -->结果：0x1
    printf("0x%x\n", LowBit(0xffffff));

    //16进制：a  -->  10进制：10 --> 二进制：1010 -->结果：0x2
    printf("0x%x\n", LowBit(0xa));

    //前缀和与区间和的关系
    unsigned n = 7;
    printf("S[%u]= \n", n);
    printf(" T[%u]\n", n);
    n = n - LowBit(n);
    printf("+ T[%u]\n", n);
    n = n - LowBit(n);
    printf("+ T[%u]\n", n);
    n = n - LowBit(n);
    printf("+ T[%u]\n", n);

    //验证letter函数
    printf("0x%x, is letter 0x%x\n", 0xabcdefab, Letter(0xabcdefab));
    printf("0x%x, is letter 0x%x\n", 0x11111111, Letter(0x11111111));
    printf("0x%x, is letter 0x%x\n", 0xa0a0a0a0, Letter(0xa0a0a0a0));
    return 0;
}
